(*# module(implementation=>off) *)
(*# module(init_code=>off) *)
(*# data(seg_name => null) *)
(*# call(o_a_copy => off,
         reg_param => (ax, dx),
         reg_saved => (bx, cx, si, di, es, ds, st1, st2),
         inline => on) *)
(*# check(stack=>off,
          index=>off,
          range=>off,
          overflow=>off,
          nil_ptr=>off) *)
DEFINITION MODULE MiscAsm;

(* By Carl Neiburger, 169 N. 25th St., San Jose, Calif. 95116 *)

TYPE
    A2 = ARRAY [0..1] OF BYTE;
    A3 = ARRAY [0..2] OF BYTE;
    A4 = ARRAY [0..3] OF BYTE;
    A5 = ARRAY [0..4] OF BYTE;
    A6 = ARRAY [0..5] OF BYTE;

INLINE PROCEDURE SWAP(val: WORD): CARDINAL = A2(86H,0E0H);
(* Swaps high and low bytes of a word, so 1234H becomes 3412H *)

INLINE PROCEDURE HI(val: WORD): CARDINAL = A5(86H,0E0H, 25H,0FFH, 00H );
(* Returns high byte of word; same as val DIV 100H *)

INLINE PROCEDURE LO(val: WORD): CARDINAL = A3(25H, 0FFH, 00H );
(* Returns low byte of word; same as val MOD 100H *)

INLINE PROCEDURE not(val: BYTE): SHORTCARD = A2(0F7H, 0D0H);
(* Returns bitwize NOT of byte *)

INLINE PROCEDURE Not(val: WORD): CARDINAL = A2(0F7H, 0D0H);
(* Returns bitwize NOT of word *)

INLINE PROCEDURE LongNot(val: LONGCARD): LONGCARD = A4(0F7H, 0D0H, 0F7H, 0D2H);
(* Returns bitwize NOT of longcard *)

INLINE PROCEDURE Xor(val1, val2 : WORD): CARDINAL = A2(33H, 0C2H);
(* Returns bitwize XOR of two words *)

INLINE PROCEDURE xor(val1, val2 : BYTE): SHORTCARD = A2(32H, 0C2H);
(* Returns bitwize XOR of two bytes *)

INLINE PROCEDURE And(val1, val2 : WORD): CARDINAL = A2(23H, 0C2H);
(* Returns bitwize AND of two words *)

INLINE PROCEDURE and(val1, val2 : BYTE): SHORTCARD = A2(22H, 0C2H);
(* Returns bitwize AND of two bytes *)

INLINE PROCEDURE Or(val1, val2 : WORD): CARDINAL = A2(0BH, 0C2H);
(* Returns bitwize OR of two words *)

INLINE PROCEDURE or(val1, val2 : BYTE): SHORTCARD = A2(0AH, 0C2H);
(* Returns bitwize OR of two bytes *)

INLINE PROCEDURE Ctl(val: BYTE): SHORTCARD = A2(34H, 40H);
(* used to flip the 6th bit in Kermit protocol *)

END MiscAsm.
